package edu.xmut.yuepai.publish.controller;

import cn.hutool.core.map.MapUtil;
import edu.xmut.yuepai.common.result.R;
import edu.xmut.yuepai.model.form.BlogPublishForm;
import edu.xmut.yuepai.model.form.YuePaiPublishForm;
import edu.xmut.yuepai.publish.service.PublishService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/publish")
public class PublishController {

    @Resource
    private PublishService publishService;

    @PostMapping("/blog")
    public R publishBlog(@RequestBody BlogPublishForm blogPublishForm, HttpServletRequest request) {
        Long id = publishService.publishBlog(blogPublishForm, request);
        HashMap<String, String> data = MapUtil.of("id", id.toString());
        return R.ok(data);
    }

    @PostMapping("/yuepai")
    public R publishYuePai(@RequestBody YuePaiPublishForm form, HttpServletRequest request) {
        Long id = publishService.publishYuePai(form, request);
        HashMap<String, String> data = MapUtil.of("id", id.toString());
        return R.ok(data);
    }


}
